#!/bin/bash

USE_CBLAS=n
if [ $# -gt 0 -a $1 == 'y' ];then
    USE_CBLAS=y
fi

if [ $# -gt 1 ];then
    make PREFIX=$2 USE_CBLAS=$USE_CBLAS
else
	make USE_CBLAS=$USE_CBLAS
fi

DATA_DIR=data

if [ ! -e $DATA_DIR/train-images.idx3-ubyte ]; then
	if [ ! -e train-images-idx3-ubyte.gz ]; then
		wget http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz
	fi

	gzip -d train-images-idx3-ubyte.gz
	mv train-images-idx3-ubyte $DATA_DIR/train-images.idx3-ubyte
fi

if [ ! -e $DATA_DIR/train-labels.idx1-ubyte ]; then
	if [ ! -e train-labels-idx1-ubyte.gz ]; then
		wget http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz
	fi

	gzip -d train-labels-idx1-ubyte.gz
	mv train-labels-idx1-ubyte $DATA_DIR/train-labels.idx1-ubyte
fi

if [ ! -e $DATA_DIR/t10k-images.idx3-ubyte ]; then
	if [ ! -e t10k-images-idx3-ubyte.gz ]; then
		wget http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz
	fi

	gzip -d t10k-images-idx3-ubyte.gz
	mv t10k-images-idx3-ubyte $DATA_DIR/t10k-images.idx3-ubyte
fi

if [ ! -e $DATA_DIR/t10k-labels.idx1-ubyte ]; then
	if [ ! -e t10k-labels-idx1-ubyte.gz ]; then
		wget http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz
	fi

	gzip -d t10k-labels-idx1-ubyte.gz
	mv t10k-labels-idx1-ubyte $DATA_DIR/t10k-labels.idx1-ubyte
fi

./mnist $DATA_DIR
